//
//  QDDetailController.m
//  simulateQuickDoctor
//
//  Created by 胡卓 on 2017/3/24.
//  Copyright © 2017年 PipiXia. All rights reserved.
//

#import "QDDetailController.h"
#import "QDNetworkTool.h"

@interface QDDetailController ()

@property(nonatomic,strong) UIWebView *webView;


@end

@implementation QDDetailController

- (void)viewDidLoad {
    [super viewDidLoad];
    
    //创建webView
    _webView = [[UIWebView alloc]initWithFrame:[UIScreen mainScreen].bounds];
    [self.view addSubview:_webView];
    
    //设置滚动速度和设置背景颜色
    _webView.scrollView.decelerationRate = UIScrollViewDecelerationRateNormal;
    _webView.backgroundColor = [UIColor whiteColor];
    
    //加载cocoaChina首页
    [self loadCocoaChina];
}


-(void) loadCocoaChina {
    
    NSString *urlString = @"https://www.baidu.com";
    
//    //创建请求
//    NSURLRequest *request = [NSURLRequest requestWithURL:[NSURL URLWithString:urlString]];
//    
    
    QDNetworkTool* tool = [QDNetworkTool sharedTool];
    
    tool.responseSerializer = [AFHTTPResponseSerializer serializer];
    
    [tool requestWithHTTPMethod:@"GET" URLString:urlString parameters:nil CallBack:^(id responseObj) {
        if (responseObj != nil) {
            NSString *htmlString = [[NSString alloc] initWithData:responseObj encoding:NSUTF8StringEncoding];
            
            [_webView loadHTMLString:htmlString baseURL:[NSURL URLWithString:urlString]];
            
        }else{
            NSLog(@"html request error");
        }
      
    }];
    
//    //发起请求
//    [[[NSURLSession sharedSession] dataTaskWithRequest:request completionHandler:^(NSData * _Nullable data, NSURLResponse * _Nullable response, NSError * _Nullable error) {
//        
//        if (error != nil) {
//            
//            NSLog(@"%@",error);
//            return;
//        }
//        
//        NSString *htmlString = [[NSString alloc] initWithData:data encoding:NSUTF8StringEncoding];
////        NSLog(@"%@", htmlString);
//        
//        [_webView loadHTMLString:htmlString baseURL:[NSURL URLWithString:urlString]];
//    }] resume];
}
@end
